//
//  theologistAppDelegate.h
//  theologist
//
//  Created by Vincenzo Fehring on 6/29/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "TrayVC.h"
#import "ChapterViewerVC.h"
#import "GestureEvent.h"
#import "globals.h"
#import "AWSSyncController.h"
#import "BWQuincyManager.h"

@class PopoverHelper;
@class AWSSyncController;
@class Language;

@interface MyWindow : UIWindow
{
    CGFloat initialDistance;
    CGFloat gestureScale;
    
    NSMutableArray *activeTouches;
    NSArray *gestureCoordStart;
    NSArray *gestureCoordEnd;
    
    id myDelegate;
}

-(BOOL)canBecomeFirstResponder;
-(void)checkGesture;
-(void)sendGestureEvent:(GestureEvent *)event;

@property (nonatomic, retain) NSArray *gestureCoordStart;
@property (nonatomic, retain) NSArray *gestureCoordEnd;
@property (nonatomic, assign) id myDelegate;

@end

@protocol MyWindowDelegate

-(void)sendGestureEvent:(GestureEvent *)event;

@optional

@end

@interface AppDelegate : NSObject <UIApplicatioNDelegate, TrayVCDelegate, MyWindowDelegate, AWSSyncControllerDelegate, BWQuincyManagerDelegate> {
    
    MyWindow *window;
    UIView *backgroundView;
    TrayVC *trayVC;
    UIAlertView *loadingAlert;
    PopoverHelper *popoverHelper;
    NSOperationQueue *sharedOperationQueue;
    
    NSManagedObjectModel *managedObjectModel;
    NSManagedObjectContext *managedObjectContext;
    NSPersistentStoreCoordinator *persistentStoreCoordinator;
    
    AWSSyncController *annotationSyncController;
    UIAlertView *alert;
}

+ (AppDelegate *)app;
+ (NSString *)device;
+ (NSString *)userAgent;

- (void)showTip:(HelpTip)t;
- (void)showTray; // zoom out and display the reader tray
- (UIViewController *)currentVC;
- (BOOL)hasInternetAccess;
- (void)showError:(NSString *)message;
- (Language *)loadDefaultLanguage;

@property (nonatomic, retain) IBOutlet UIView *backgroundView;
@property (nonatomic, retain) IBOutlet MyWindow *window;
@property (nonatomic, retain) TrayVC *trayVC;
@property (nonatomic, retain) UIAlertView *loadingAlert;
@property (nonatomic, retain) NSOperationQueue *sharedOperationQueue;

@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;

@property (retain) AWSSyncController *annotationSyncController; // to protect against a race condition where the launches and the receives an open URL request this property must be atomic.

@property (retain) UIAlertView *alertView;

- (void)startSync;

- (NSString *)applicationDocumentsDirectory;

@end